local skel = fk.CreateSkill {
  name = "efengqi__yinghun",
}

Fk:loadTranslationTable{
  ["efengqi__yinghun"] = "英魂",
  [":efengqi__yinghun"] = "准备阶段，你可以弃置一名角色任意张牌，再令一名角色摸任意张牌 （数量之和为你已损失体力值）。",

  ["#efengqi__yinghun-ask"] = "英魂：弃置一名角色若干张牌，令一名角色摸若干张牌，数量之和为:【 %arg 】",
  ["efengqi__yinghun_draw"] = "仅摸牌",
  ["efengqi__yinghun_throw"] = "先弃后摸",
  ["#efengqi__yinghun-draw"] = "英魂：令一名角色摸 %arg 张牌",
  ["efengqi__yinghun_active"] = "英魂",
  ["#efengqi__yinghun-throw"] = "英魂：弃置 %dest 至多 %arg 张牌",

  ["$efengqi__yinghun1"] = "以吾魂魄，保佑吾儿之基业。",
  ["$efengqi__yinghun2"] = "不诛此贼三族，则吾死不瞑目！",
}

skel:addEffect(fk.EventPhaseStart, {
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Start and player:isWounded()
  end,
  on_cost = function (self, event, target, player, data)
    local success, dat = player.room:askToUseActiveSkill(player, { skill_name = "efengqi__yinghun_active",
    prompt = "#efengqi__yinghun-ask:::"..player:getLostHp()})
    if success and dat then
      event:setCostData(self, dat)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).targets[1]
    local n = player:getLostHp()
    if event:getCostData(self).interaction == "efengqi__yinghun_draw" then
      to:drawCards(n, skel.name)
    else
      local cards = room:askToChooseCards(player, { target = to, min = 1, max = n, flag = "he", skill_name = skel.name,
       prompt = "#efengqi__yinghun-throw::"..to.id..":"..n})
      room:throwCard(cards, skel.name, to, player)
      n = n - #cards
      if n > 0 then
        local tos = room:askToChoosePlayers(player, { targets = room.alive_players, min_num = 1, max_num = 1,
        prompt = "#efengqi__yinghun-draw:::"..n, skill_name = skel.name, cancelable = false})
        to = tos[1]
        to:drawCards(n, skel.name)
      end
    end
  end,
})

return skel
